#ifndef IMG_DATA_H
#define IMG_DATA_H
#include <mat.h>

#include <matrix.h>
#include "sharedStructure.hpp"
#include <string>
#include <list>
/*
* This class is designed as a structure for holding image data read from mat file.
* Specifically, no math operations should be done. 
* Functions are all should be related to data IO
*/
class imgData{
public:
	imgData(){};
	~imgData(){};

	int n_orient,n_length;
	int l_range2,o_range2;
	int l_range,o_range;

	int h;
	int sx,sy; /*image height and width respectively*/
	float **S1map;
	float **S2map;
	float **M2map;
	
	float **allsymbol;
	float **C;
	unsigned char *img_r,*img_g,*img_b;
	unsigned char *gray_img;
	unsigned char *color_a_map,*color_b_map,*color_l_map;
	unsigned char *mo_map;

	std::string mat_file_name;


	line lineVertex2Line(const lineVertex &source);
	bool readDataFromMatFile(const char* file_name);
	bool release();
	lineVertex matlabLine2lineVertex(const line &source);

private:
	void* matGetPointer(MATFile* p_file, const char* var_name);
	double matGetScalar(MATFile *p_file, const char *var_name);
	bool loadCellSingle(const MATFile *p_file,const char* var_name, int n1, int n2, float **&maps);
	void deleteMaps(float **maps, int n);
    std::list<mxArray*> mem_ptr; /*mxArrays that are stil in memory*/
    bool releaseMatMemory();
};



#endif
